// const winston = require('../../../../tasks/util/winstonLogger.js');
addressModalController.$inject = ['$scope', '$location', 'addressService', 'addressInfo', '$uibModalInstance','getAllAddressList'];
function addressModalController($scope, $location, addressService, addressInfo, $modalInstance,getAllAddressList) {
    
    var vm = this;
    $scope.addressInfo = addressInfo;
    $scope.cancel = function () {
        console.log("close the modal");
        $modalInstance.dismiss('cancel');
    }

    $scope.submitAddressForm = function () {
        addressService.addCustomerAddr(addressInfo, function (error, result) {
            if (error) {
                console.log("error " + error.message);
            }
            else {
                //增加成功
                console.log(result);
                if (result.nModified == 1 && result.ok == 1) {
                    console.log("success to call back");
                    $scope.cancel();
                    getAllAddressList();
                }
                else {
                    console.log("fail to update");
                    alert("sorry,出错了");
                    $scope.cancel();
                }

            }
        })
    }
}
module.exports = addressModalController;

